package com.xxl.job.kettle.core.controller;

import com.xxl.job.kettle.core.entity.KtrFileEntity;
import com.xxl.job.kettle.core.service.KtrFileService;
import com.xxl.job.kettle.result.Result;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

/**
 * 实现功能：
 *
 * @author 作者[zk]
 * @version 1.0.00  2022-12-08 10:53
 */
@RestController
@RequestMapping("/ktr/file")
public class KtrFileController extends BaseController<KtrFileEntity, KtrFileService> {

    @PostMapping("/upload")
    public Result<KtrFileEntity> upload(MultipartFile file) throws IOException {
        KtrFileEntity entity = KtrFileEntity.builder().name(file.getOriginalFilename())
                .fileSize(file.getSize()).ktrFile(file.getBytes()).build();
        service.getBaseMapper().insert(entity);
        return Result.OK("保存成功", entity);
    }
}
